<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label" >项目类别</label>
         <div class="layui-input-inline">
            <el-select v-model="selectData.chacypidEqual" placeholder="请选择项目类别">
              <el-option label="全部" :value="null"></el-option>
              <el-option v-for="item in chargeProjectTypes" :key="item.value" :label="item.label" :value="item.value"/>
            </el-select>
         </div>
      </div>
     <div class="layui-inline">
        <label class="layui-form-label" >项目状态</label>
         <div class="layui-input-inline">
        <el-select v-model="selectData.chastatusEqual" placeholder="请选择项目状态">
          <el-option label="全部" :value="null"></el-option>
          <el-option v-for="item in chaStatusTypes" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
         </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label" >项目名称</label>
         <div class="layui-input-inline">
            <el-input  v-model="selectData.nameLike" placeholder="请输入辖区"></el-input>
         </div>
      </div>
      <el-button type="primary"  @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button  @click="btnRepeat">重置</el-button>
    </div>
    <div>
      <ul class="toolList">
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
        <!-- <li @click="operate('查看历史价格')">
          <el-button type="primary">查看历史价格</el-button>
        </li> -->
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

    <chargeProjectManageMain ref="sweetModalMain" :orderType="order" @refreshData="getData"></chargeProjectManageMain>
    <!-- 查看历史价格 -->
    <sweet-modal ref="dialogLSPrice" class="dialog" :sweetModalWidth="sweetModalWidth" :sweetModalMaxWidth="sweetModalMaxWidth">
      <h3>{{ title }}</h3>
      <br/>
      <dataTable :headList="headListLSJG" :dataList="dataListLSJG" :pageOrder="pageOrderLSJG" @pageChange="pageChangeLSJG" :hiddenColumn="hiddenColumn"></dataTable>
    </sweet-modal>
    <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import chargeProjectManageMain from "./chargeProjectManageMain";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import staEndUse from "../basic/staEndUse";
import { ORDER } from "@/const/orderConst.js";
import { manage } from "@/mixins/managePage.js";

const ADD = "新增";
const MODIFYPROJECT = "修改";
const MODIFYPRICE = "价格修改";
const DELETE = "删除";
const INFO = "详情";
const CKLSJG = "历史价格查询";
const ADDPRICE = "新增实收限价";

export default {
  name: "chargeProjectManage",
  mixins: [manage],
  data() {
    return {
      title: null,
      loading: false,
      chargeProjectTypes: [],
      chaStatusTypes: [],
      chaReductionTypes: [],
      chaUintsTypes: [],

      selectData: {},
      chaData: {},

      //价格历史
      dataListLSJG: [],
      headListLSJG: [],
      //分页和排序
      pageOrderLSJG: {
        orderType: null,
        orderSort: null,
        totalNum: null,
        pageSize: 10,
        currentPage: 1
      },
      sweetModalWidth: 80,
      sweetModalMaxWidth: 840,
      hiddenColumn: false
    };
  },
  methods: {
    //收费项目查询
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.Query,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //收费项目历史价格查询
    getPriceHistory() {
      let data = {
        PageIndex: this.pageOrderLSJG.currentPage,
        PageSize: this.pageOrderLSJG.pageSize,
        OrderBy: this.pageOrderLSJG.orderType,
        OrderByType: this.pageOrderLSJG.orderSort,
        Data: { CpechaidEqual: this.currentRow.CHAID }
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.QueryPriceHistory,
        res => {
          this.dataListLSJG = res.data.content.OutData;
          this.pageOrderLSJG.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //分页和排序
    pageChangeLSJG(value) {
      this.pageOrderLSJG = value;
      this.getPriceHistory();
    },
    //分页和排序
    pageChange(value) {
      this.pageOrder = value;
      this.getData();
    },
    //获取收费项目类别
    getChargeProjectType() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.QueryType,
        res => {
          let cdhTypeData = res.data.content,
            legendsCdhData = cdhTypeData.map(item => ({
              label: item.CYPNAME,
              value: item.CYPID
            }));
          this.chargeProjectTypes = legendsCdhData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取收费项目状态
    getChaStatus() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.ChaStatus,
        res => {
          let cdhTypeData = res.data.content,
            legendsCdhData = cdhTypeData.map(item => ({
              label: item.Text,
              value: item.Value
            }));
          this.chaStatusTypes = legendsCdhData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取减免项目
    getChargeProjectReduction() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.QueryReduction,
        res => {
          let cdhTypeData = res.data.content,
            legendsCdhData = cdhTypeData.map(item => ({
              label: item.REDNAME,
              value: item.REDID
            }));
          this.chaReductionTypes = legendsCdhData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取计量单位
    getUint() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetUint,
        res => {
          let cdhTypeData = res.data.content,
            legendsCdhData = cdhTypeData.map(item => ({
              label: item.CodeName,
              value: item.CodeValue
            }));
          this.chaUintsTypes = legendsCdhData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取表头
    getChargeProjectColumn() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetChargeProjectColumns,
        res => {
          this.headList = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取历史价格表头
    getProjectPriceColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetChargeProjectPriceColumns,
        res => {
          this.headListLSJG = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.$refs.sweetModalMain.open(this.order);
          break;
        case MODIFYPROJECT:
        case MODIFYPRICE:
        case INFO:
        case DELETE:
         this.$refs.sweetModalMain.open(this.order, this.currentRow.CHAID);
          break;
        case ADDPRICE:  //新增实收限价 (上虞) 
        this.$refs.sweetModalMain.open(this.order, this.currentRow.CHAID,this.currentRow.CHANAME);
          break; 
        case CKLSJG:
          this.openDialogLSPrice();
          break;
        case ORDER.START:
        case ORDER.END:
          this.$refs.useMain.open(this.order, this.currentRow.CHAID);
          break;
        default:
      }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if (this.currentRow) {
        status = this.currentRow.CHASTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case INFO:
        case MODIFYPROJECT:
        case ADDPRICE:
        case MODIFYPRICE:
        case DELETE:
        case CKLSJG:
          return status !== '';
          break;
        case ORDER.END:
          return status === '正常';
          break;
        case ORDER.START:
          return status === '禁用';
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.chaData = {};
    },
    openDialogLSPrice() {
      this.order = CKLSJG;
      this.title = "收费项目历史价格查询";
      this.sweetModalWidth = 80;
      this.sweetModalMaxWidth = 1310;
      this.hiddenColumn = false;
      this.getPriceHistory();
      this.$refs.dialogLSPrice.open();
    }
  },
  components: {
    sweetModal,
    dataTable,
    chargeProjectManageMain,
    staEndUse
  },
  mounted() {},
  created() {
    this.getChargeProjectColumn();
    this.getData();
    this.getChargeProjectType();
    this.getChaStatus();
    this.getChargeProjectReduction();
    this.getUint();
    this.getProjectPriceColumns();
  }
};
</script>
